package cn.swh.guguanjia.mapper;

import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/11/14 16:17
 * @Version: 1.0
 */
public class SysOfficeProvider {

    public String selectPage(Map<String,Object> map){
        return new SQL(){{
            SELECT("so.*, " +
                    " sa.`name` area_name ");
            FROM(" sys_office so, " +
                    " sys_area sa ");
            WHERE(" so.area_id=sa.id " );
            WHERE(" so.del_flag=0");
            if (map.containsKey("sid") && !StringUtils.isEmpty(map.get("sid"))) {
                WHERE("so.parent_ids LIKE CONCAT('%',#{sid},'%') OR sa.id=#{sid}");
            }else if (map.containsKey("name") && !StringUtils.isEmpty(map.get("name"))) {
                WHERE("sa.`name` LIKE CONCAT('%',#{name},'%')");
            }
        }}.toString();
    }

}
